<template>
	<!-- 校友 -->
	<view class="alumni-container">
		<!-- 导航区 -->
		<SearchHeader placeholder="搜索你的校友" @setSearchValue="getSearchValue">
			<!-- 右侧图标 -->
			<template #right>
				<view class="search-right">
					<!-- 筛选学院 -->
					<navigator url="/pages/screenColleges/screenColleges" class="search-header-icon1">
						<image src="/static/img/alumni/screen.png" mode="widthFix"></image>
					</navigator>
					<!-- 交换名片 -->
					<navigator url="/pages/Business_card/Business_card" class="search-header-icon">
						<image src="/static/img/alumni/commute.png" mode="widthFix"></image>
					</navigator>
				</view>
			</template>

			<!-- tabs区 -->
			<template #tabs>
				<view class="mytabs">
					<u-tabs :list="tabsList" lineWidth="60rpx" lineHeight="4rpx" :inactiveStyle="{
						fontSize: '28rpx',
						fontFamily: 'Source Han Sans CN-Regular, Source Han Sans CN',
						fontWeight: 400,
						color: '#999999',
						lineHeight: '37rpx'}" :activeStyle="{
						fontSize: '28rpx',
						fontFamily: 'Source Han Sans CN-Medium, Source Han Sans CN',
						fontWeight: 500,
						color: '#333',
						lineHeight: '37rpx'
					}" @change="handleTabs"></u-tabs>
				</view>
			</template>
		</SearchHeader>

		<!-- 列表 -->
		<view class="alumnus-list">
			<navigator class="alumnus-list-item" :url="'/pages/Other_card/Other_card?id='+item.id" v-for="item in alumnusList"
				:key="item.id">
				<!-- 头像 -->
				<view class="alumnus-list-item-l">
					<image :src="item.img"></image>
				</view>
				<view class="alumnus-list-item-r">
					<!-- 姓名 -->
					<view class="alumnus-list-item-r-name">{{item.name}}</view>
					<!-- 详情 -->
					<view class="alumnus-list-item-r-info">
						<view class="alumnus-list-item-r-info-date">{{item.school_time}}</view>
						<view class="alumnus-list-item-r-info-major">{{item.major}}</view>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import SearchHeader from '@/componets/SearchHeader/SearchHeader.vue'
	import icon from '../../uni_modules/uview-ui/libs/config/props/icon'
	export default {
		data() {
			return {
				// tabs列表
				tabsList: [],

				// 校友列表
				alumnusList: [],

				// 分页
				page: 1,

				// 条目
				limit: 10,

				// type
				type: 1,

				// 学院
				college: ''
			}
		},

		methods: {

			/**
			 * 获取tabs列表
			 */
			getTabsList() {
				this.$request.post({
					url: '/api/users/menuList',
					success: res => {
						if (res.code != 200) return uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.tabsList = res.result
					}
				})
			},

			/**
			 * 获取校友列表
			 */
			getAlumnusList() {
				this.$request.post({
					url: '/api/users/alumniList',
					data: {
						page: this.page,
						limit: this.limit,
						type: this.type,
						name: this.name,
						college: this.college
					},
					success: res => {
						if (res.code != 200) return uni.showToast({
							title: res.msg
						})

						this.alumnusList = [...this.alumnusList, ...res.result.result]
						console.log(this.alumnusList, 'alumnusList')
					},
					fail: err => {
						console.log(err, 'err')
					}
				})
			},

			/**
			 * 获取改变后的搜索框的值
			 * @param {string} value 搜索框的值
			 */
			getSearchValue(value) {
				this.name = value
				this.alumnusList = []
				this.getAlumnusList()
			},

			/**
			 * 点击了tabs
			 * @param {object} value 点击的tabs项具体内容
			 */
			handleTabs(value) {
				this.type = value.type
				this.alumnusList = []
				this.getAlumnusList()
			},
		},

		components: {
			SearchHeader
		},

		onLoad() {
			this.getTabsList()
		},

		onShow() {
			if (uni.getStorageSync('college')) {
				this.college = uni.getStorageSync('college').name
				uni.removeStorageSync('college')
			}
			this.alumnusList = []
			this.getAlumnusList()
		}
	}
</script>

<style lang="less" scoped>
	.alumni-container {
		width: 100%;
		min-height: 100vh;
		background-color: #fff;

		.search-right {
			display: flex;
			align-items: center;
		}

		.search-header-icon1 {
			width: 48rpx;
			height: 48rpx;
			margin-right: 32rpx;
			margin-left: 32rpx;

			>image {
				width: 100%;
			}
		}

		.search-header-icon {
			width: 48rpx;
			height: 48rpx;
			margin-right: 200rpx;

			>image {
				width: 100%;
			}
		}

		.mytabs {
			width: 100%;
			overflow: hidden;
			border-bottom: 2rpx solid #f1f1f1;

			/deep/.u-tabs__wrapper__nav__item {
				padding: 0 39rpx !important;
			}
		}

		.alumnus-list {
			width: 100%;
			margin-top: 20rpx;
			overflow: hidden;
			padding: 0 40rpx;
			box-sizing: border-box;

			&-item {
				width: 100%;
				padding: 20rpx 0;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				border-bottom: 2rpx solid #f1f1f1;

				&-l {
					width: 92rpx;
					height: 92rpx;
					border-radius: 50%;
					overflow: hidden;

					>image {
						width: 100%;
					}
				}

				&-r {
					flex: 1;
					height: 92rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin-left: 20rpx;

					&-name {
						font-size: 28rpx;
						font-family: Source Han Sans CN-Medium, Source Han Sans CN;
						font-weight: 500;
						color: #333333;
						line-height: 28rpx;
					}

					&-info {
						display: flex;
						font-size: 24rpx;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #666666;
						line-height: 34rpx;
						letter-spacing: 1px;

						&-date {
							margin-right: 20rpx;
						}
					}
				}
			}
		}
	}
</style>